<?php

class AuthController extends Silk_Controller_Action {

    public function loginAction(){

	if ($this->_request->isPost()){

	    $username = $this->_getParam('username');
	    $password = $this->_getParam('password');

// 	    $authAdapter = new Silk_Auth_Adapter($username, $password);

	    $result = Silk::PasswordAuthenticate($username, $password);

	    if ($result){

		logdebug('AuthController.action_login: Authentication successful');

		$session = Silk::GetSession();

		if (isset($session->acl_requested_uri)){
		    $uri = $session->acl_requested_uri;
		    unset($session->acl_requested_uri);
		    logdebug('AuthController.action_login: Redirecting to ' . $uri);
		    return $this->_redirect($uri);
		} else {
		    logdebug('AuthController.action_login: Redirecting to dashboard');
		    $this->gotoRoute('dashboard');
		}

	    } else
		$this->notifications('Invalid username/password', NOTIFY_ERROR);

	} else
	    $this->view->username = '';

    }

    public function logoutAction(){

	Silk::DeAuthenticate();
	$this->gotoRoute('login');

    }
}

?>